import wx


class MyFrame(wx.Frame):
    eve = 0

    def __init__(self):
        super().__init__(parent=None, title="vbox", size=(500, 200), pos=(50, 100))  # 继承wx.Frame类
        self.Center()
        self.panel = wx.Panel(parent=self)  # 面板
        vbox = wx.BoxSizer(wx.VERTICAL)

        self.bmps = [
            wx.Bitmap('F:\P_008.jpg', wx.BITMAP_TYPE_JPEG),
            wx.Bitmap('F:\P_005.jpg', wx.BITMAP_TYPE_JPEG)
        ]
        self.image = wx.StaticBitmap(self.panel, -1, self.bmps[0])

        b1 = wx.Button(self.panel, id=1, label='变换图片')
        self.Bind(wx.EVT_BUTTON, self.on_click, b1)

        vbox.Add(b1, 1, wx.CENTER)
        vbox.Add(self.image, 5, wx.CENTER)

        self.panel.SetSizer(vbox)

    def on_click(self, event):
        event_id = event.GetId()
        if self.eve % 2 == 0:
            self.image.SetBitmap(self.bmps[1])

        else:
            self.image.SetBitmap(self.bmps[0])
        self.eve = self.eve + 1
        self.panel.Layout()
        #   界面刷新


class App(wx.App):
    def OnInit(self):  # 进入
        frame = MyFrame()
        frame.Show()
        return True

    def OnExit(self):  # 退出
        print("tuichu")
        return 0


if __name__ == '__main__':
    app = App()
    app.MainLoop()

